﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class add_table_StdViewContainerDict : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<DateTime>(
                name: "CreationTime",
                table: "MainStdTableDict",
                type: "timestamp with time zone",
                nullable: false,
                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));

            migrationBuilder.AddColumn<Guid>(
                name: "CreatorId",
                table: "MainStdTableDict",
                type: "uuid",
                nullable: true);

            migrationBuilder.AddColumn<DateTime>(
                name: "LastModificationTime",
                table: "MainStdTableDict",
                type: "timestamp with time zone",
                nullable: true);

            migrationBuilder.AddColumn<Guid>(
                name: "LastModifierId",
                table: "MainStdTableDict",
                type: "uuid",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "MainStdViewContainerDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    TopicDictId = table.Column<Guid>(type: "uuid", nullable: false),
                    StdViewContainerName = table.Column<string>(type: "text", nullable: false),
                    Exp = table.Column<string>(type: "text", nullable: true),
                    ViewContainerTemplateType = table.Column<int>(type: "integer", nullable: false),
                    Size = table.Column<string>(type: "text", nullable: false),
                    Layout = table.Column<string>(type: "text", nullable: false),
                    Gutter = table.Column<int>(type: "integer", nullable: false),
                    LabelWidth = table.Column<int>(type: "integer", nullable: false),
                    Title = table.Column<string>(type: "text", nullable: false),
                    NoColon = table.Column<bool>(type: "boolean", nullable: false),
                    Bordered = table.Column<bool>(type: "boolean", nullable: false),
                    StdApiConfigId = table.Column<Guid>(type: "uuid", nullable: true),
                    DefaultFlag = table.Column<bool>(type: "boolean", nullable: false),
                    Ver = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStdViewContainerDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStdViewContainerDict_MainStdApiConfig_StdApiConfigId",
                        column: x => x.StdApiConfigId,
                        principalTable: "MainStdApiConfig",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_MainStdViewContainerDict_MainTopicDict_TopicDictId",
                        column: x => x.TopicDictId,
                        principalTable: "MainTopicDict",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainStdViewDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Col = table.Column<int>(type: "integer", nullable: false),
                    Label = table.Column<string>(type: "text", nullable: false),
                    Unit = table.Column<string>(type: "text", nullable: false),
                    Type = table.Column<string>(type: "text", nullable: false),
                    Optional = table.Column<string>(type: "text", nullable: false),
                    OptionalHelp = table.Column<string>(type: "text", nullable: false),
                    OptionalHelpColor = table.Column<string>(type: "text", nullable: false),
                    NoColon = table.Column<bool>(type: "boolean", nullable: false),
                    HideLabel = table.Column<bool>(type: "boolean", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    StdViewContainerDictId = table.Column<Guid>(type: "uuid", nullable: true),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStdViewDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStdViewDict_MainStdViewContainerDict_StdViewContainerDi~",
                        column: x => x.StdViewContainerDictId,
                        principalTable: "MainStdViewContainerDict",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "MainStdViewValueDict",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Prefix = table.Column<string>(type: "text", nullable: false),
                    Unit = table.Column<string>(type: "text", nullable: false),
                    Tooltip = table.Column<string>(type: "text", nullable: false),
                    Size = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    StdViewDictId = table.Column<Guid>(type: "uuid", nullable: true),
                    CreationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uuid", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStdViewValueDict", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStdViewValueDict_MainStdViewDict_StdViewDictId",
                        column: x => x.StdViewDictId,
                        principalTable: "MainStdViewDict",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainStdViewContainerDict_StdApiConfigId",
                table: "MainStdViewContainerDict",
                column: "StdApiConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_MainStdViewContainerDict_TopicDictId",
                table: "MainStdViewContainerDict",
                column: "TopicDictId");

            migrationBuilder.CreateIndex(
                name: "IX_MainStdViewDict_StdViewContainerDictId",
                table: "MainStdViewDict",
                column: "StdViewContainerDictId");

            migrationBuilder.CreateIndex(
                name: "IX_MainStdViewValueDict_StdViewDictId",
                table: "MainStdViewValueDict",
                column: "StdViewDictId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "MainStdViewValueDict");

            migrationBuilder.DropTable(
                name: "MainStdViewDict");

            migrationBuilder.DropTable(
                name: "MainStdViewContainerDict");

            migrationBuilder.DropColumn(
                name: "CreationTime",
                table: "MainStdTableDict");

            migrationBuilder.DropColumn(
                name: "CreatorId",
                table: "MainStdTableDict");

            migrationBuilder.DropColumn(
                name: "LastModificationTime",
                table: "MainStdTableDict");

            migrationBuilder.DropColumn(
                name: "LastModifierId",
                table: "MainStdTableDict");
        }
    }
}
